import { createStore } from 'vuex'
import { getParkSetAPI } from "@/api/parksetting"
import { getMemberListAPI } from '@/api/member'

// 创建一个新的 store 实例
const store = createStore({
  state() {
    return {
      loginState: false,
      parkSet: [],
      member: [],
      parksettotal: Number(localStorage.getItem('parksettotal')) || 10,
      membertotal: Number(localStorage.getItem('membertotal')) || 10,
      collapse: false
    }
  },
  mutations: {
    // 获取登录状态
    CHANGE_LOGINSTATE(state: any, payload: boolean) {
      state.loginState = payload;
    },

    // 获取停车场信息
    GET_PARKSET(state: any) {
      getParkSetAPI({
        pageSize: state.parksettotal
      }).then((res: any) => {
        // console.log(res);
        localStorage.setItem('parksettotal', res.total)
        state.parkSet.splice(0, state.parkSet.length, ...res.data)
      })
    },

    //获取会员信息
    GET_MEMBER(state: any) {
      getMemberListAPI({
        pageSize: state.membertotal
      }).then((res: any) => {
        // console.log(res);
        localStorage.setItem('membertotal', res.total)
        state.member.splice(0, state.member.length, ...res.data)
      })
    },

    // 改变菜单折叠状态
    CHANGE_COLLAPSE(state: any) {
      state.collapse = !state.collapse;
    },

  },
  getters:{
    CHANGE_COLLAPSE(state: any) {
      return state.collapse
    }

  },
  /* actions: {
     GET_PARKSET (context:any,payload:any) {
       context.commit('GET_PARKSET',payload)
       console.log('context',context);
       console.log('payload',payload);
     }
   }*/
})

export default store

